package com.ruoyi.system.api.factory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteAiService;

/**
 * AI服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteAiFallbackFactory implements FallbackFactory<RemoteAiService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteAiFallbackFactory.class);

    @Override
    public RemoteAiService create(Throwable throwable)
    {
        log.error("AI服务调用失败:{}", throwable.getMessage());
        return new RemoteAiService()
        {
            @Override
            public R<String> chat(String prompt, String chatId, String source)
            {
                return R.fail("AI服务暂时不可用，请稍后重试");
            }

            @Override
            public R<String> healthCheck(String message, String source)
            {
                return R.fail("AI服务健康检查失败");
            }
        };
    }
}
